<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('站内信列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>状态：</label>
                            <select name="innerMessageStatus"
                                    th:with="type=${@dict.getType('inner_message_status')}" required>
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}" ></option>
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="search" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">

<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >-->
<!--                <i class="fa fa-remove"></i> 删除-->
<!--            </a>-->

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var messageStatus = [[${@dict.getType('inner_message_status')}]];
    var messageType = [[${@dict.getType('inner_message_type')}]];
    var prefix = ctx + "gy/innerMessage";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            pageSize:7,
            modalName: "站内信",
            columns: [
                {
                    field: 'messageId',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'memo',
                    title: '信件内容'
                },

                {
                    field: 'user.userName',
                    title: '接受者'
                },
                {
                    field: 'user.phonenumber',
                    title: '接受者联系电话'
                },
                {
                    field: 'messageType',
                    title: '分类',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(messageType, value);
                    }
                },
                {
                    field: 'innerMessageStatus',
                    title: '站内信状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(messageStatus, value);
                    }
                },
                {
                    field: 'sendTime',
                    title: '发信时间'
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(row.innerMessageStatus == "0" || row.innerMessageStatus == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="setRead(\'' + row.messageId + '\')">标记已读<a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.messageId + '\')">删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function setRead(messageId){
        $.modal.confirm("确定已读该条信息吗？", function () {
            $.operate.saveModal(prefix + "/setRead", {"messageId": messageId}, function () {
                $("#search").click();
            });
        });
    }
</script>
</body>
</html>
